package pe.edu.upc.dew.Grupo1.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.support.WebApplicationContextUtils;

import pe.edu.upc.dew.Grupo1.model.Funcion;
import pe.edu.upc.dew.Grupo1.model.Local;
import pe.edu.upc.dew.Grupo1.service.FuncionService;
import pe.edu.upc.dew.Grupo1.service.LocalService;


/**
 * Servlet implementation class ListaFuncionServlet
 */
public class ListaFuncionServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private FuncionService funcionService;   
	
    public ListaFuncionServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    @Override
	public void init(ServletConfig config) throws ServletException {
		this.funcionService = WebApplicationContextUtils
		.getWebApplicationContext(config.getServletContext()).getBean(
				"funcionService", FuncionService.class);
	
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {	
		
		HttpSession session=req.getSession();
		if(session.getAttribute("usuario") == null)
		{
			req.getRequestDispatcher("login.jsp").forward(req,resp);	
			return;
		}
		
		Funcion funcion=new Funcion();
		funcion.setCodigoFuncion(0);
		
		List<Funcion> lista=funcionService.GetFuncionesPorPelicula(funcion);
		
		req.setAttribute("funciones", lista);
		
		req.getRequestDispatcher("lista_fun.jsp").forward(req,
				resp);
	}

}
